﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BigGuy : Enemy
{
    public Transform PickPoint;
    public float power = 10;

    public void PickBomb()
    { //Animation Event
        if (targetPoint && targetPoint.CompareTag("Bomb") && !hasBomb)
        {
            targetPoint.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic;
            targetPoint.SetParent(PickPoint);
            targetPoint.position = PickPoint.position;
            hasBomb = true;
        }
    }

    public void ThrowBomb()
    { //Animation Evnet
        if (hasBomb && targetPoint)
        {
            targetPoint.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
            targetPoint.SetParent(transform.parent.parent);
            //查找对象节点
            if (FindObjectOfType<PlayerConllter>().gameObject.transform.position.x - transform.position.x < 0)
            {
                targetPoint.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1, 1) * power, ForceMode2D.Impulse);
            }
            else
            {
                targetPoint.GetComponent<Rigidbody2D>().AddForce(new Vector2(1, 1) * power, ForceMode2D.Impulse);
            }
        }
        hasBomb = false;
    }
}
